// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const { ccclass, property } = cc._decorator;

@ccclass
export default class Box extends cc.Component {
    // @property(cc.Collider)
    // _collider: cc.Collider = null;

    private _velocity: cc.Vec2 = cc.Vec2.ZERO;
    private _hW: number = 0;
    private _hH: number = 0;
    private _originColor: cc.Color = cc.Color.GREEN;
    private _collisionColor: cc.Color = cc.Color.RED;
    protected start(): void {
        this._velocity.x = (Math.random() * 2 - 1) * 200;
        this._velocity.y = (Math.random() * 2 - 1) * 200;
        this._hW = cc.winSize.width * 0.5;
        this._hH = cc.winSize.height * 0.5;
        this._originColor = this.node.color;

    }
    protected update(dt: number): void {
        // return;
        // this.node.x += (Math.random() * 2 - 1) * 50;
        // this.node.y += (Math.random() * 2 - 1) * 50;

        this.node.x += this._velocity.x * dt;
        this.node.y += this._velocity.y * dt;
        if (this.node.x < -this._hW || this.node.x > this._hW) {
            this._velocity.x *= -1;
        }

        if (this.node.y < -this._hH || this.node.y > this._hH) {
            this._velocity.y *= -1;
        }
    }

    onCollisionEnter(other?, self?) {
        cc.log('onCollisionEnter');
        // self.node.color = this._collisionColor;

    }

    onCollisionStay(other?, self?) {
        
    }

    onCollisionExit(other, self) {
        cc.log('onCollisionExit');
        // self.node.color = this._originColor;
    }
}
